Telefon rehberini çekme işlemi While döngüsü sorunu
31.05.2016 - 10:06
izlemiş olduğum bir derste anlatılanı yazdım
ancak her isime tüm numaraların 2 katı kadar rehbere kişi ekleyip gösteriyor
yani 100 kişi varsa a ismini 200 sefer gösteriyor.
Bu sorunun ikinci while dan kaynaklandığını düşünüyorum
ancak konuda yetersiz olduğumdan çözemedim. Bakabilir misiniz.
package com.milcanx.cont_provider;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class Content_Provider_Act extends AppCompatActivity {
final List<Kisi> kisiler = new ArrayList<Kisi>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_content__provider_act);
final ListView list = (ListView) findViewById(R.id.lvList);
OzelAdapter adapter = new OzelAdapter(this, kisiler);
list.setAdapter(adapter);
final Uri content_uri = ContactsContract.Contacts.CONTENT_URI;
final String ID = ContactsContract.Contacts._ID;
final String Isim = ContactsContract.Contacts.DISPLAY_NAME;
final String Tel_Durumu = ContactsContract.Contacts.HAS_PHONE_NUMBER;
final Uri Phone_uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
final String Phone_ID = ContactsContract.CommonDataKinds.Phone.CONTACT_ID;
final String Phone_Number = ContactsContract.CommonDataKinds.Phone.NUMBER;
ContentResolver contentresolver = getContentResolver();
Cursor cursor = contentresolver.query(content_uri, null, null, null, null);
assert cursor != null;
while (cursor.moveToNext()) {
String kisi_id = cursor.getString(cursor.getColumnIndex(ID));
String kisi_isim = cursor.getString(cursor.getColumnIndex(Isim));
String tel_durum = cursor.getString(cursor.getColumnIndex(Tel_Durumu));
Bitmap photo = null;
try {
InputStream inputstream = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), ContentUris.withAppendedId(content_uri, Long.valueOf(kisi_id)));
if (inputstream != null) photo = BitmapFactory.decodeStream(inputstream);
if (inputstream != null) {
inputstream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
if (tel_durum.equals("1")) {
Cursor phonecursor = contentresolver.query(Phone_uri, null, Phone_ID + " -?", new String[]{kisi_id}, null);
assert phonecursor != null;
while (phonecursor.moveToNext()) {
final String t = phonecursor.getString(phonecursor.getColumnIndex(Phone_Number));
Kisi k = new Kisi(kisi_isim, t);
k.photo = photo;
kisiler.add(k);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + kisiler.get(position).getTel_no()));
startActivity(i);
}
});
}
phonecursor.close();
}
}
}
}
19
Görüntülenme
0 Beğeni